import com.alibaba.fastjson.JSONObject;
import top.codedance.iotp.common.util.HexCodec;
import top.codedance.iotp.iot.sdk.StandandService;
import top.codedance.iotp.iot.sdk.entity.*;
import top.codedance.iotp.iot.sdk.po.slave.SlaveBaseParam;
import top.codedance.iotp.iot.sdk.po.slave.SlaveDataParam;
import top.codedance.iotp.iot.sdk.po.sync.*;
import org.junit.Test;

import java.util.*;

public class StandandTestSdk {
    private HexCodec hc = new HexCodec();

    @Test
    public void oprationSlave(){
        StandandService standandService = new StandandService("http://127.0.0.1:10015", 60);
        SlaveBaseParam slaveBaseParam = new SlaveBaseParam();
        slaveBaseParam.setUsername("admin");
        slaveBaseParam.setPassword("123456");
        SlaveDataParam slaveDataParam = new SlaveDataParam();
        SlaveItem slaveItem1 = new SlaveItem(1, 16, 0, 14, 327.69); //小端字节序数据
        slaveDataParam.add(slaveItem1);
        SlaveItem slaveItem2 = new SlaveItem(1, 16, 4, 14);
        slaveItem2.setBeValue(888.999); //大端字节序数据
        slaveDataParam.add(slaveItem2);
        slaveBaseParam.setData(slaveDataParam);
        JSONObject jsonObject = standandService.opration(slaveBaseParam);
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void registryHealthy(){
        StandandService standandService = new StandandService("http://127.0.0.1:10014", 60);
        JSONObject jsonObject = standandService.registryHealthy();
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void registryInformation(){
        StandandService standandService = new StandandService("http://127.0.0.1:10014", 60);
        JSONObject jsonObject = standandService.registryInformation();
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void serverListOnRegistry(){
        StandandService standandService = new StandandService("http://127.0.0.1:10014", 60);
        JSONObject jsonObject = standandService.serverListOnRegistry();
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void serverInfomation(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012", 60);
        BaseParam baseParam = new BaseParam();
        baseParam.setUsername("admin");
        baseParam.setPassword("codedance2021");
        JSONObject jsonObject = standandService.serverInfomation(baseParam);
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void getAllRegistedDeviceIds(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012");
        BaseParam baseParam = new BaseParam();
        baseParam.setUsername("admin");
        baseParam.setPassword("codedance2021");
        JSONObject jsonObject = standandService.getAllRegistedDeviceIds(baseParam);
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void addDevices(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012");
        AddDeviceParam addDeviceParam = new AddDeviceParam();
        addDeviceParam.setUsername("admin");
        addDeviceParam.setPassword("codedance2021");
        DeviceEntity deviceEntity = new DeviceEntity();
        deviceEntity.setId(1); //此条可填可不填，如果不填服务端使用自增长，如果填需要自行维护此主键，不能与服务端的主键值冲突
        deviceEntity.setDeviceId(UUID.randomUUID().toString());
        deviceEntity.setUnitName(UUID.randomUUID().toString());
        DeviceEntity deviceEntity1 = new DeviceEntity();
        deviceEntity1.setId(2); //此条可填可不填，如果不填服务端使用自增长，如果填需要自行维护此主键，不能与服务端的主键值冲突
        deviceEntity1.setDeviceId(UUID.randomUUID().toString());
        deviceEntity1.setUnitName(UUID.randomUUID().toString());
        List<DeviceEntity> devices = new ArrayList<DeviceEntity>();
        devices.add(deviceEntity);
        devices.add(deviceEntity1);
        addDeviceParam.setDevices(devices);
        JSONObject jsonObject = standandService.addDevices(addDeviceParam);
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void deleteDevices(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012");
        DeleteDevicceParam deleteDevicceParam = new DeleteDevicceParam();
        deleteDevicceParam.setUsername("admin");
        deleteDevicceParam.setPassword("codedance2021");
        deleteDevicceParam.setId("4");
        JSONObject jsonObject = standandService.deleteDevices(deleteDevicceParam);
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void listDevices(){
        StandandService distributedService = new StandandService("http://127.0.0.1:10012");
        BaseParam baseParam = new BaseParam();
        baseParam.setUsername("admin");
        baseParam.setPassword("codedance2021");
        JSONObject jsonObject = distributedService.listDevices(baseParam);
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void addUsers(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012");
        AddUserParam addUserParam = new AddUserParam();
        addUserParam.setUsername("admin");
        addUserParam.setPassword("codedance2021");
        UserEntity userEntity = new UserEntity();
        userEntity.setId(1); //此条可填可不填，如果不填服务端使用自增长，如果填需要自行维护此主键，不能与服务端的主键值冲突
        userEntity.setDeviceId(UUID.randomUUID().toString());
        userEntity.setIsAdmin(0);
        userEntity.setPassword("test01");
        userEntity.setUsername("test01");
        UserEntity userEntity1 = new UserEntity();
        userEntity1.setId(2); //此条可填可不填，如果不填服务端使用自增长，如果填需要自行维护此主键，不能与服务端的主键值冲突
        userEntity1.setDeviceId(UUID.randomUUID().toString());
        userEntity1.setIsAdmin(0);
        userEntity1.setPassword("test01");
        userEntity1.setUsername("test01");
        List<UserEntity> users = new ArrayList<UserEntity>();
        users.add(userEntity);
        users.add(userEntity1);
        addUserParam.setUsers(users);
        JSONObject jsonObject = standandService.addUsers(addUserParam);
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void deleteUser(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012");
        DeleteUserParam deleteUserParam = new DeleteUserParam();
        deleteUserParam.setUsername("admin");
        deleteUserParam.setPassword("codedance2021");
        deleteUserParam.setId("6");
        JSONObject jsonObject = standandService.deleteUser(deleteUserParam);
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void listUsers(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012");
        BaseParam baseParam = new BaseParam();
        baseParam.setUsername("admin");
        baseParam.setPassword("codedance2021");
        JSONObject jsonObject = standandService.listUsers(baseParam);
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void setClientVersion(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012");
        SetClientVersionParam setClientVersionParam = new SetClientVersionParam();
        setClientVersionParam.setUsername("admin");
        setClientVersionParam.setPassword("codedance2021");
        setClientVersionParam.setVersionCode(2);
        JSONObject jsonObject = standandService.setClientVersion(setClientVersionParam);
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void setClientPluginsParams(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012", "d1");
        SetClientPluginsParamsParam setClientPluginsParamsParam = new SetClientPluginsParamsParam();
        setClientPluginsParamsParam.setUsername("u1");
        setClientPluginsParamsParam.setPassword("u1");
        Map<String, Map<String, String>> params = new HashMap<>();
        Map<String, String> mysqlParams = new HashMap<>();
        mysqlParams.put("jdbcUrl.0", "jdbc:mysql://10.229.40.252:3306/epsdb?characterEncoding=UTF-8&serverTimezone=GMT%2B8");
        mysqlParams.put("user.0", "root_s");
        mysqlParams.put("password.0", "root@s");
        params.put("mysql", mysqlParams);
        Map<String, String> mssqlParams = new HashMap<>();
        mssqlParams.put("jdbcUrl.0", "jdbc:sqlserver://10.229.40.252:3306;databaseName=epsdb");
        mssqlParams.put("user.0", "root_s");
        mssqlParams.put("password.0", "root@s");
        params.put("mssql", mssqlParams);
        Map<String, String> oracleParams = new HashMap<>();
        oracleParams.put("jdbcUrl.0", "jdbc:oracle:thin:@localhost:1521:SID");
        oracleParams.put("user.0", "root_s");
        oracleParams.put("password.0", "root@s");
        params.put("oracle", oracleParams);
        Map<String, String> opcParams = new HashMap<>();
        opcParams.put("type.0", "da");
        opcParams.put("endpointUrl.0", "opc.tcp://192.168.0.45:49380");
        opcParams.put("namespace.0", "2");
        opcParams.put("host.0", "192.168.0.114");
        opcParams.put("domain.0", "");
        opcParams.put("progId.0", "SWToolbox.TOPServer.V5");
        opcParams.put("user.0", "codedance");
        opcParams.put("password.0", "123456");
        params.put("opc", opcParams);
        Map<String, String> opwParams = new HashMap<>();
        opwParams.put("application.0", "1");
        opcParams.put("useComNum.0", "1");
        opwParams.put("newBaudRate.0", "9600");
        opwParams.put("newDataBits.0", "8");
        opwParams.put("newStopBits.0", "1");
        opwParams.put("newParity.0", "0");
        params.put("opw", opwParams);
        Map<String, String> modbusParams = new HashMap<>();
        modbusParams.put("host.0", "192.168.0.45");
        modbusParams.put("port.0", "502");
        params.put("modbus", modbusParams);
        Map<String, String> liveParams = new HashMap<>();
        liveParams.put("ffmpegPath", "D:/working/ffmpeg/bin/ffmpeg.exe");
        params.put("live", liveParams);
        setClientPluginsParamsParam.setParams(params);
        JSONObject jsonObject = standandService.setClientPluginsParams(setClientPluginsParamsParam);
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void getClientPluginsParams(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012", "d1");
        ClientBaseParam clientBaseParam = new ClientBaseParam();
        clientBaseParam.setUsername("u1");
        clientBaseParam.setPassword("u1");
        JSONObject jsonObject = standandService.getClientPluginsParams(clientBaseParam);
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void execGenericDB(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012", "d6");
        ExecGenericDbParam execGenericDbParam = new ExecGenericDbParam();
        execGenericDbParam.setUsername("u6");
        execGenericDbParam.setPassword("u6");
        DbClientParam dbClientParam = new DbClientParam();
        dbClientParam.setId(0);
        dbClientParam.setSql("select * from users");
        execGenericDbParam.setClient(dbClientParam);
        JSONObject jsonObject = standandService.execGenericDB(execGenericDbParam);
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void execSql(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012", "d1");
        ExecSqlParam execSqlParam = new ExecSqlParam();
        execSqlParam.setUsername("u1");
        execSqlParam.setPassword("u1");
        DbClientParam dbClientParam = new DbClientParam();
        dbClientParam.setId(0);
        dbClientParam.setSql("select * from oil_send");
        execSqlParam.setClient(dbClientParam);
        JSONObject jsonObject = standandService.execSql(execSqlParam);
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void execMysql(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012", "d1");
        ExecMysqlParam execMysqlParam = new ExecMysqlParam();
        execMysqlParam.setUsername("u1");
        execMysqlParam.setPassword("u1");
        DbClientParam dbClientParam = new DbClientParam();
        dbClientParam.setId(0);
        dbClientParam.setSql("select * from oil_send");
        execMysqlParam.setClient(dbClientParam);
        JSONObject jsonObject = standandService.execMysql(execMysqlParam);
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void execMssql(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012", "d6");
        ExecMssqlParam execMssqlParam = new ExecMssqlParam();
        execMssqlParam.setUsername("u6");
        execMssqlParam.setPassword("u6");
        DbClientParam dbClientParam = new DbClientParam();
        dbClientParam.setId(0);
        dbClientParam.setSql("select * from users");
        execMssqlParam.setClient(dbClientParam);
        JSONObject jsonObject = standandService.execMssql(execMssqlParam);
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void execOracle(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012", "d1");
        ExecOracleParam execOracleParam = new ExecOracleParam();
        execOracleParam.setUsername("u1");
        execOracleParam.setPassword("u1");
        DbClientParam dbClientParam = new DbClientParam();
        dbClientParam.setId(0);
        dbClientParam.setSql("select * from \"book\" b");
        execOracleParam.setClient(dbClientParam);
        JSONObject jsonObject = standandService.execOracle(execOracleParam);
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void execCom(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012", "d3");
        ExecComParam execComParam = new ExecComParam();
        execComParam.setUsername("u3");
        execComParam.setPassword("p3");
        ComClientParam comClientParam = new ComClientParam();
        comClientParam.setId(0);
        //直接传字符串
//        comClientParam.setCommand("55 AA 01 00 00");

        //传递字节数组
        byte[] bytes = hc.toBytes("55AA010000");
        comClientParam.setCommand(bytes);

        execComParam.setClient(comClientParam);
        JSONObject jsonObject = standandService.execCom(execComParam);
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void execUdp(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012", "d3");
        ExecUdpParam execUdpParam = new ExecUdpParam();
        execUdpParam.setUsername("u3");
        execUdpParam.setPassword("p3");
        UdpClientParam udpClientParam = new UdpClientParam();
        udpClientParam.setId(0);

        //直接传字符串
//        udpClientParam.setCommand("xuedianfu");

        //传递字节数组
        byte[] bytes = hc.toBytes("1CFE00000000FFE7");
        udpClientParam.setCommand(bytes);

        execUdpParam.setClient(udpClientParam);
        JSONObject jsonObject = standandService.execUdp(execUdpParam);
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void execOpc(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012", "d6", 120);
        ExecOpcParam execOpcParam = new ExecOpcParam();
        execOpcParam.setUsername("u6");
        execOpcParam.setPassword("u6");
        OpcClientParam opcClientParam = new OpcClientParam();
        opcClientParam.setId(0);
        List<Object> tags = new ArrayList<>();
        tags.add("模拟器示例.函数.Ramp1");
        opcClientParam.setTags(tags);
        execOpcParam.setClient(opcClientParam);
        JSONObject jsonObject = standandService.execOpc(execOpcParam);
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void execOpcGetNodes(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012", "d3");
        ExecOpcParam execOpcParam = new ExecOpcParam();
        execOpcParam.setUsername("u3");
        execOpcParam.setPassword("u3");
        OpcClientParam opcClientParam = new OpcClientParam();
        opcClientParam.setId(1);
        opcClientParam.setData(new JSONObject());
        execOpcParam.setClient(opcClientParam);
        JSONObject jsonObject = standandService.execOpc(execOpcParam);
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void execOpc2(){
        StandandService standandService = new StandandService("http://127.0.0.1:10022", "d2");
        ExecOpcParam execOpcParam = new ExecOpcParam();
        execOpcParam.setUsername("u2");
        execOpcParam.setPassword("u2");
        OpcClientParam opcClientParam = new OpcClientParam();
        opcClientParam.setId(0);
        List<Object> tags = new ArrayList<>();
        OpcSubParam osp1 = new OpcSubParam();
        osp1.setNs(2);
        osp1.setTag("alarm.test.t1");
        osp1.setIsWrite(false);
        osp1.setValue(111);
        JSONObject tmpJo = new JSONObject();
        tmpJo.put("id", 2343434);
        osp1.setExt(tmpJo);
        tags.add(osp1);
        opcClientParam.setTags(tags);
        execOpcParam.setClient(opcClientParam);
        JSONObject jsonObject = standandService.execOpc(execOpcParam);
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void execModbus(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012", "d3");
        ExecModBusParam execModBusParam = new ExecModBusParam();
        execModBusParam.setUsername("u3");
        execModBusParam.setPassword("p3");
        ModbusClientParam modbusClientParam = new ModbusClientParam();
        modbusClientParam.setId(2);
        ModbusEntity modbusEntity = new ModbusEntity();
        modbusEntity.setTag("test1");
        modbusEntity.setFunction(3);
        modbusEntity.setSlaveId(1);
        modbusEntity.setOffset(0);
        modbusEntity.setDatatype(14);
        modbusEntity.setIsWrite(false);
        modbusEntity.setValue(1);
        ModbusEntity modbusEntity1 = new ModbusEntity();
        modbusEntity1.setTag("test2");
        modbusEntity1.setFunction(3);
        modbusEntity1.setSlaveId(1);
        modbusEntity1.setOffset(4);
        modbusEntity1.setDatatype(14);
        modbusEntity1.setIsWrite(false);
        modbusEntity1.setValue(1);
        List<ModbusEntity> modbusEntities = new ArrayList<>();
        modbusEntities.add(modbusEntity);
        modbusEntities.add(modbusEntity1);
        modbusClientParam.setItems(modbusEntities);
        execModBusParam.setClient(modbusClientParam);
        JSONObject jsonObject = standandService.execModbus(execModBusParam);
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void execModbus2(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012", "d3");
        ExecModBusParam execModBusParam = new ExecModBusParam();
        execModBusParam.setUsername("u3");
        execModBusParam.setPassword("p3");
        ModbusClientParam modbusClientParam = new ModbusClientParam();
        modbusClientParam.setId(2);
        ModbusNodesEntity modbusNodesEntity = new ModbusNodesEntity();
        modbusNodesEntity.setFirst(0);
        modbusNodesEntity.setDevices(16);
        modbusClientParam.setData(modbusNodesEntity);
        execModBusParam.setClient(modbusClientParam);
        JSONObject jsonObject = standandService.execModbus(execModBusParam);
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void execBacNet(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012", "d6");
        ExecBacNetParam execBacNetParam = new ExecBacNetParam();
        execBacNetParam.setUsername("u6");
        execBacNetParam.setPassword("u6");
        BacNetClientParam bacNetClientParam = new BacNetClientParam();
        bacNetClientParam.setId(0);
        BacNetEntity bacNetEntity1 = new BacNetEntity();
        bacNetEntity1.setTag("tag1");
        bacNetEntity1.setDeviceId(3113167);
        bacNetEntity1.setProperty(85);
        bacNetEntity1.setDatatype(0);
        bacNetEntity1.setInstance(0);
        BacNetEntity bacNetEntity2 = new BacNetEntity();
        bacNetEntity2.setTag("tag2");
        bacNetEntity2.setDeviceId(3113168);
        bacNetEntity2.setProperty(85);
        bacNetEntity2.setDatatype(0);
        bacNetEntity2.setInstance(0);
        List<BacNetEntity> bacnetList = new ArrayList<>();
        bacnetList.add(bacNetEntity1);
        bacnetList.add(bacNetEntity2);
        bacNetClientParam.setItems(bacnetList);
        execBacNetParam.setClient(bacNetClientParam);
        JSONObject jsonObject = standandService.execBacnet(execBacNetParam);
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void execBacNet2(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012", "d6");
        ExecBacNetParam execBacNetParam = new ExecBacNetParam();
        execBacNetParam.setUsername("u6");
        execBacNetParam.setPassword("u6");
        BacNetClientParam bacNetClientParam = new BacNetClientParam();
        bacNetClientParam.setId(0);
        bacNetClientParam.setData(new BacNetNodesEntity());
        execBacNetParam.setClient(bacNetClientParam);
        JSONObject jsonObject = standandService.execBacnet(execBacNetParam);
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void execModbusCheckSlaves(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012", "d2");
        ExecModBusParam execModBusParam = new ExecModBusParam();
        execModBusParam.setUsername("u2");
        execModBusParam.setPassword("u2");
        ModbusClientParam modbusClientParam = new ModbusClientParam();
        modbusClientParam.setId(2);
        ModbusNodesEntity modbusNodesEntity = new ModbusNodesEntity();
        modbusNodesEntity.setFirst(2);
        modbusNodesEntity.setDevices(3);
        modbusClientParam.setData(modbusNodesEntity);
        execModBusParam.setClient(modbusClientParam);
        JSONObject jsonObject = standandService.execModbus(execModBusParam);
        System.out.println(jsonObject.toJSONString());
    }

    /**
     * 测试cmd命令
     */
    @Test
    public void ExecSystem(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012", "d1");
        ExecSystemParam execSystemParam = new ExecSystemParam();
        execSystemParam.setUsername("u1");
        execSystemParam.setPassword("u1");
        execSystemParam.setCommand("netstat -ano");
        JSONObject jsonObject = standandService.ExecSystem(execSystemParam);
        System.out.println(jsonObject.toJSONString());
    }

    /**
     * 执行powershell命令
     */
    @Test
    public void ExecSystem2(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012", "d1");
        ExecSystemParam execSystemParam = new ExecSystemParam();
        execSystemParam.setUsername("u1");
        execSystemParam.setPassword("u1");
        PowershellSubParam powershellSubParam = new PowershellSubParam();
        powershellSubParam.setCmd("powershell Get-Process | Sort-Object WorkingSet -Descending | Select -First 10");
        powershellSubParam.setPowershell(true);
        execSystemParam.setCommand(powershellSubParam);
        JSONObject jsonObject = standandService.ExecSystem(execSystemParam);
        System.out.println("***********************************************************************************************");
        System.out.println(jsonObject.get("data"));
        System.out.println("***********************************************************************************************");
    }

    /**
     * 测试内网测试机器
     */
    @Test
    public void ExecSystem3(){
        StandandService standandService = new StandandService("http://192.168.0.111:10012", "d1");
        ExecSystemParam execSystemParam = new ExecSystemParam();
        execSystemParam.setUsername("u1");
        execSystemParam.setPassword("u1");
        execSystemParam.setCommand("powershell Get-Process | Sort-Object WorkingSet -Descending | Select -First 10");
        JSONObject jsonObject = standandService.ExecSystem(execSystemParam);
        System.out.println("***********************************************************************************************");
        System.out.println(jsonObject.get("data"));
        System.out.println("***********************************************************************************************");
    }

    /**
     * 测试油库生产环境
     */
    @Test
    public void ExecSystem4(){
        StandandService standandService = new StandandService("http://192.168.0.170:10012", "63095BD3-DD31-492E-BD19-F1037FA21E12");
        ExecSystemParam execSystemParam = new ExecSystemParam();
        execSystemParam.setUsername("bee434c6-9e91-4320-83fa-596728e8d7e9");
        execSystemParam.setPassword("16191562458905555");
        //服务名 tasklist /fi "SERVICES eq iot-client"
        //程序名 tasklist /fi "IMAGENAME eq java.exe"
        //内存 tasklist /fi "MEMUSAGE gt 512000"
        //进程 tasklist /fi "PID eq 17640"
        //模块 tasklist /m wrapper.dll
        // wmic cpu get loadpercentage
        // wmic OS get FreePhysicalMemory
        // wmic ComputerSystem get TotalPhysicalMemory
        // powershell Enable-PSRemoting –Force
        // Set-Item -Force wsman:\\localhost\\Client\\TrustedHosts -value 192.168.0.*
        // Restart-Service WinRM

        //测试连接    Test-WsMan xxx.xxx.xxx.xxx
        //登陆      Enter-PSSession 192.168.0.165 -Credential Administrator
        execSystemParam.setCommand("tasklist /fi \"IMAGENAME eq java.exe\"");
        JSONObject jsonObject = standandService.ExecSystem(execSystemParam);
        System.out.println("***********************************************************************************************");
        System.out.println(jsonObject.get("data"));
        System.out.println("***********************************************************************************************");
    }

    @Test
    public void ExecHttp(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012", "d6", 120);
        ExecHttpParam execHttpParam = new ExecHttpParam();
        execHttpParam.setUsername("u6");
        execHttpParam.setPassword("u6");
        HttpCommandEntity httpCommandEntity = new HttpCommandEntity();
        httpCommandEntity.setMethod(HttpCommandEntity.Method.post);
        httpCommandEntity.setProtocol(HttpCommandEntity.Protocol.http);
        httpCommandEntity.setUrl("//192.168.0.67/test.php");
        HttpHeaders headers = new HttpHeaders();
        headers.put("Content-Type", "application/json;charset=utf-8");
        headers.put("token", "dfidsf8ewrjf7df8");
        httpCommandEntity.setHeaders(headers);
        httpCommandEntity.setRequestBody("{\"a\": \"aa\", \"b\": \"bb\", \"c\": \"cc\"}");
        execHttpParam.setCommand(httpCommandEntity);
        JSONObject jsonObject = standandService.execHttp(execHttpParam);
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void ExecPushData(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012", "d1");
        ExecPushDataParam execPushDataParam = new ExecPushDataParam();
        execPushDataParam.setUsername("u1");
        execPushDataParam.setPassword("u1");
        PushDataParam pushDataParam = new PushDataParam();
        pushDataParam.setId(0);
        execPushDataParam.setClient(pushDataParam);
        JSONObject jsonObject = standandService.execPushData(execPushDataParam);
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void ShutdownClient(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012", "d3");
        ShutdownClientParam shutdownClientParam = new ShutdownClientParam();
        shutdownClientParam.setUsername("u3");
        shutdownClientParam.setPassword("u3");
        ShutdownClientSubParam scsp = new ShutdownClientSubParam();
        scsp.setIsExceptionExit(true);
        scsp.setAmount(1);
        shutdownClientParam.setClient(scsp);
        JSONObject jsonObject = standandService.shutdownClient(shutdownClientParam);
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void viewClientVersion(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012", "d5");
        BaseParam baseParam = new BaseParam();
        baseParam.setUsername("u5");
        baseParam.setPassword("u5");
        JSONObject jsonObject = standandService.viewClientVersion(baseParam);
        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void viewClientInfomation(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012", "d5");
        BaseParam baseParam = new BaseParam();
        baseParam.setUsername("u5");
        baseParam.setPassword("u5");
        JSONObject jsonObject = standandService.viewClientInfomation(baseParam);
        System.out.println(jsonObject.toJSONString());
    }
}
